package com.weblog.weblog.admin.controller;

import com.weblog.weblog.admin.model.vo.category.AddCategoryReqVO;
import com.weblog.weblog.admin.model.vo.category.DeleteCategoryReqVO;
import com.weblog.weblog.admin.model.vo.category.FindCategoryPageListReqVO;
import com.weblog.weblog.admin.service.AdminCategoryService;
import com.weblog.weblog.common.aspect.ApiOperationLog;
import com.weblog.weblog.common.utils.PageResponse;
import com.weblog.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gc
 * @class_name AdminCategoryController
 * @date 2023年09月20日 13:51
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "Admin 分类管理")
public class AdminCategoryController {


    private final AdminCategoryService categoryService;

    public AdminCategoryController(AdminCategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @PostMapping("/category/add")
    @ApiOperation(value = "添加分类")
    @ApiOperationLog(description = "添加分类")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response addCategory(@RequestBody @Validated AddCategoryReqVO addCategoryReqVO){
        return categoryService.addCategory(addCategoryReqVO);
    }

    @PostMapping("/category/list")
    @ApiOperation(value = "分类分页数据查询")
    @ApiOperationLog(description = "分类分页数据查询")
    public PageResponse findCategoryPageList(@RequestBody @Validated FindCategoryPageListReqVO findCategoryPageListReqVO){
        return categoryService.findCategoryPageList(findCategoryPageListReqVO);
    }

    @PostMapping("/category/delete")
    @ApiOperation(value = "删除分类")
    @ApiOperationLog(description = "删除分类")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response deleteCategory(@RequestBody @Validated DeleteCategoryReqVO deleteCategoryReqVO) {
        return categoryService.deleteCategory(deleteCategoryReqVO);
    }

    @PostMapping("/category/select/list")
    @ApiOperation(value = "分类Select 下拉列表数据获取")
    @ApiOperationLog(description = "分类Select 下拉列表数据获取")
    public Response findCategorySelectList(){
        return categoryService.findCategorySelectList();
    }
}
